<template>
    <div class="ant-tab-pane">
        <div class="tab-name" :class="{'active': isActive}" v-text="name" @click="handleClick"></div>
        <div class="tab-content" v-show="isActive">
            <slot></slot>
        </div>
    </div>
</template>
<script>
import eventBus from './eventBus'
export default {
  props: {
    name: {
      type: String,
      default: ''
    },
    active: {
      type: Boolean,
      default: function () {
        return false
      }
    }
  },
  data () {
    return {
      isActive: false
    }
  },
  created () {
    this.isActive = this.active
    eventBus.$on('tabChange', (val) => {
      this.isActive = (this.name === val)
    })
  },
  methods: {
    handleClick () {
      eventBus.$emit('tabChange', this.name)
    }
  }
}
</script>
<style scoped>
.ant-tab-pane{
  display: inline-block;
}
.tab-name{
  width: 100px;
  height: 50px;
  background-color: lightblue;
  color: #fff;
  text-align: center;
  line-height: 50px;
}
.active{
  background-color: #fff;
  color: lightblue;
}
.tab-content{
  position: absolute;
  width: 100%;
  height: 500px;
  background-color: #eee;
  left: 0;
}
</style>
